﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;

namespace LDTB
{
    public partial class UserFrm : Form
    {
        LDTBDataDataContext ds = DataService.DB;

        public UserFrm()
        {
            InitializeComponent();
        }

        private void UserFrm_Load(object sender, EventArgs e)
        {

            FillToForm();

        }

        public void FillToForm() {

            var us = from u in ds.Users
                     select new { ID = u.ID, UserName = u.UserName, FullName = u.FullName };

            this.dataGridView1.DataSource = us;

        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UserAddFrm ua = new UserAddFrm();
            ua.ShowDialog();

            FillToForm();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            int uid = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());

            UserEditFrm u = new UserEditFrm(uid);
            u.ShowDialog();
            FillToForm();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
